package com.clei.enums;

import java.util.Arrays;
import java.util.Map;
import java.util.stream.Collectors;

/**
 * 日期转换类型 enum
 *
 * @author Y
 * @date 2022-12-06
 */
public enum DateConvertTypeEnum {
    /*
     *String -> Long
     */
    STRING_LONG(0),
    /*
     *String -> LocalDateTime
     */
    STRING_LOCALDATETIME(1),
    /*
     *String -> LocalDate
     */
    STRING_LOCALDATE(2),
    /*
     *String -> Date
     */
    STRING_DATE(3),
    /*
     *Long -> String
     */
    LONG_STRING(4),
    /*
     *Long -> LocalDateTime
     */
    LONG_LOCALDATETIME(5),
    /*
     *Long -> LocalDate
     */
    LONG_LOCALDATE(6),
    /*
     *Long -> Date
     */
    LONG_DATE(7),
    /*
     *LocalDateTime -> String
     */
    LOCALDATETIME_STRING(8),
    /*
     *LocalDateTime -> Long
     */
    LOCALDATETIME_LONG(9),
    /*
     *LocalDateTime -> LocalDate
     */
    LOCALDATETIME_LOCALDATE(10),
    /*
     *LocalDateTime -> Date
     */
    LOCALDATETIME_DATE(11),
    /*
     *LocalDate -> String
     */
    LOCALDATE_STRING(12),
    /*
     *LocalDate -> Long
     */
    LOCALDATE_LONG(13),
    /*
     *LocalDate -> LocalDateTime
     */
    LOCALDATE_LOCALDATETIME(14),
    /*
     *LocalDate -> Date
     */
    LOCALDATE_DATE(15),
    /*
     *Date -> String
     */
    DATE_STRING(16),
    /*
     *Date -> Long
     */
    DATE_LONG(17),
    /*
     *Date -> LocalDateTime
     */
    DATE_LOCALDATETIME(18),
    /*
     *Date -> LocalDate
     */
    DATE_LOCALDATE(19);

    /**
     * name -> DateConvertTypeEnum map
     */
    private static final Map<String, DateConvertTypeEnum> NAME_MAP = Arrays.stream(DateConvertTypeEnum.values())
            .collect(Collectors.toMap(DateConvertTypeEnum::name, e -> e));

    /**
     * code
     */
    private final Integer code;

    DateConvertTypeEnum(Integer code) {
        this.code = code;
    }

    /**
     * 根据name获取枚举
     *
     * @param name name
     * @return DateConvertTypeEnum
     */
    public static DateConvertTypeEnum getByName(String name) {
        return null == name ? null : NAME_MAP.get(name);
    }

    public Integer getCode() {
        return code;
    }
}

